/*
 * @Description:
 * @Author:
 * @Date: 2024-10-26 11:38:47
 * @LastEditTime: 2024-12-22 22:24:43
 * @LastEditors: XXX
 */
import { AppActionTypes } from './action-types'
import { AppMutationTypes } from './mutation-types'

import type { ActionTree, ActionContext } from 'vuex'
import type { AppState, DeviceType } from './state'
import type { RootState } from '@/store'
import type { Mutations } from './mutations'

type AugmentedActionContext = {
  commit<K extends keyof Mutations> (
    key: K,
    payload: Parameters<Mutations[K]>[1]
  ): ReturnType<Mutations[K]>
} & Omit<ActionContext<AppState, RootState>, 'commit'>

export interface Actions {
  [AppActionTypes.ACTION_TOGGLE_SIDEBAR] ({ commit }: AugmentedActionContext, withoutAnimation: boolean): void
  [AppActionTypes.ACTION_CLOSE_SIDEBAR] ({ commit }: AugmentedActionContext, withoutAnimation: boolean): void
  [AppActionTypes.ACTION_SET_LANGUAGE] ({ commit }: AugmentedActionContext, language: string): void
  [AppActionTypes.ACTION_TOGGLE_DEVICE] ({ commit }: AugmentedActionContext, device: DeviceType): void
  [AppActionTypes.ACTION_SET_SIZE] ({ commit }: AugmentedActionContext, size: string): void
}

export const actions: ActionTree<AppState, RootState> & Actions = {
  [AppActionTypes.ACTION_TOGGLE_SIDEBAR]: function ({ commit }: AugmentedActionContext, withoutAnimation: boolean): void {
    commit(AppMutationTypes.TOGGLE_SIDEBAR, withoutAnimation)
  },

  [AppActionTypes.ACTION_CLOSE_SIDEBAR]: function ({ commit }: AugmentedActionContext, withoutAnimation: boolean): void {
    commit(AppMutationTypes.CLOSE_SIDEBAR, withoutAnimation)
  },

  [AppActionTypes.ACTION_SET_LANGUAGE]: function ({ commit }: AugmentedActionContext, language: string): void {
    commit(AppMutationTypes.SET_LANGUAGE, language)
  },

  [AppActionTypes.ACTION_TOGGLE_DEVICE]: function ({ commit }: AugmentedActionContext, device: DeviceType): void {
    commit(AppMutationTypes.TOGGLE_DEVICE, device)
  },

  [AppActionTypes.ACTION_SET_SIZE]: function ({ commit }: AugmentedActionContext, size: string): void {
    commit(AppMutationTypes.SET_SIZE, size)
  }
}
